<template>
    <div class="page-order-list">
        <div class="page-header">
            <div @click="tomy" class="page-header-left">
                <span class="page-header-back"></span>
            </div>
            <div class="page-header-title line-ellipsis">订单列表</div>
            <div class="page-header-right">
                <div class="nav-btn">
                    <img src="../assets/images/nav-button.png" alt="" class="nav-icon">
                </div>
            </div>
        </div>
        <div class="order-list" v-if="orderlist">
            <div class="order-item" v-for="(item,index) in orderlist" :key="index">
                <div class="order-title border-1px-b">
                    <span class="cinema-name line-ellipsis">{{item.cinema}}</span>
                    <span class="arrow"></span>
                    <span class="right" v-if="!item.isfinish">待消费</span>
                    <span class="right" v-if="item.isfinish">已完成</span>
                </div>
                <div class="order-detail-info">
                    <div class="order-info">
                        <img :src="item.movieImg" alt="">
                        <div class="order-desc">
                            <div class="movie-name line-ellipsis">
                                <span>{{item.movieNm}} {{item.seat.length}}张</span>
                            </div>
                            <div class="ff-tag-empty"></div>
                            <div class="showTime line-ellipsis">
                                {{item.paytime}}
                            </div>
                            <div class="position line-ellipsis">
                                {{item.hall}}
                                <span class="seat" v-for="(k,i) in item.seat" :key="i">{{k.row}}排{{k.col}}座</span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="order-more">
                    <div class="price">总价：{{item.allprice}}元</div>
                    <span class="right">
                        <span class="bottom-btn" @click="showOrder(item.id)" v-if="!item.isfinish">去消费</span>
                        <span class="bottom-btn" @click="delorder(item.id)" v-if="item.isfinish">删除订单</span>
                    </span>
                </div>
            </div>
        </div>
        <!-- <van-cell is-link @click="showPopup">展示弹出层</van-cell> -->
        <van-overlay :show="show" @click="close" height="150px">
            <img src="../assets/images/orderImg.png" alt="">
            <div class="font" style="font-size:15px">订单号:{{orderId}}</div>
         </van-overlay>
    </div>
</template>

<script>
import { ref } from "vue";
import { useRouter } from "vue-router";
    export default {
      setup() {
               const router=useRouter()
               let orderlist=ref([])
               let finishfalse=ref(null)
               let showfalse=ref(null)
               let show=ref(false)
               let orderIndex=ref(null)
               let orderId=ref(null)
            let tomy=()=>{
                router.push('/my')
            }
           let delorder=(id)=>{
                let index = orderlist.value.findIndex(item=>item.id==id)
                orderlist.value.splice(index,1)
                window.localStorage.setItem("orderlist",JSON.stringify(orderlist.value))
            }
          let  showOrder=(id)=>{
                show.value=!show.value
                if (show.value) {
                    getTime()
                }
                let index = orderlist.value.findIndex(item=>item.id==id)
                orderIndex.value=index
            }
           let close=()=>{
                // console.log(orderIndex);
                show.value=false
                orderlist.value[orderIndex.value].isfinish=true
                window.localStorage.setItem("orderlist",JSON.stringify(orderlist.value))
            }
           let getTime=()=>{
                let d = new Date()
                orderId.value=d.getTime()
                // console.log(orderId);
            }
              let temp = JSON.parse(window.localStorage.getItem("orderlist"))
            if (temp) {
                orderlist.value=[...orderlist.value,...temp]
            }
            
                return {
                orderlist,
                finishfalse,
                showfalse,
                orderIndex,
                orderId,
                tomy,
                delorder,
                showOrder,
                close,
                show,
            };
      }
        
    }
</script>

<style lang="less" scoped>
.page-order-list{
    width: 100%;
    background: #f3f3f3;
    height: 100%;
    overflow-y: hidden;

    .page-header{
        display: flex;
        height: 50px;
        text-align: center;
        color: #fff;
        background: #e54848;

        .page-header-left{
            width: 50px;
            height: 100%;
            line-height: 50px;

            .page-header-back{
                display: inline-flex;
                position: relative;
                width: 16px;
                height: 16px;
                vertical-align: middle;

                &::before{
                    content: "";
                    position: absolute;
                    top: 0;
                    width: 100%;
                    height: 100%;
                    box-sizing: border-box;
                    border-bottom: 2px solid #fff;
                    border-left: 2px solid #fff;
                    transform: rotate(45deg);
                }
            }
        }
        .page-header-title{
            flex: 1;
            line-height: 50px;
            font-size: 18px;
            font-weight: 400;
        }
        .page-header-right{
                position: relative;
                display: flex;
                align-items: center;
                width: 50px;
                height: 100%;
                line-height: 50px;

                .nav-btn{
                    flex: 1;
                    text-align: right;
                    margin-right: 6px;

                    .nav-icon{
                        display: inline-block;
                        width: 17px;
                        height: 16px;
                    }
                }
        }
    }
    .order-list{
        height: 100%;
        overflow-y: auto;
        position: relative;

        .order-item{
            height: 184px;
            background-color: #fff;
            margin-top: 10px;

            .order-title {
                display: flex;
                align-items: center;
                padding: 0 15px;
                position: relative;

                .cinema-name{
                    display: inline-block;
                    text-align: left;
                    line-height: 38px;
                    height: 38px;
                    font-size: 13px;
                    color: #666;
                    margin-right: 6px;
                }
               .right{
                margin: 0 0 0 auto;
                color: #999;
                line-height: 38px;
                font-size: 14px;
                }
               &::after{
                position: absolute;
                left: 0;
                bottom: 0;
                height: 1px;
                width: 100%;
                content: "";
                transform: scaleY(.5);
                transform-origin: 0 0;
                background: rgba(0,0,0,.1);
               }
            }
            .order-detail-info{
                height: 82px;
                padding: 13px 15px;

                .order-info{
                    height: 82px;
                    position: relative;
                    display: flex;
                    align-items: center;

                    &>img{
                        flex: 0 0 auto;
                        width: 57px;
                        height: 80px;
                    }
                    .order-desc{
                        flex: 1 1 auto;
                        margin-left: 14px;
                        margin-top: 0;
                        overflow: hidden;

                        .movie-name{
                            height: 22px;
                            line-height: 22px;
                            font-weight: 500;
                            font-family: PingFangSC-Medium;
                            font-size: 16px;
                            color: #000;
                            letter-spacing: 0;
                            margin-bottom: 5px;
                        }
                        .ff-tag-empty{
                            height: 14px;
                            margin: 0;
                        }
                        .showTime{
                            font-size: 12px;
                            color: #888;
                            line-height: 18px;
                            height: 18px;
                        }
                        .position{
                            font-size: 12px;
                            color: #888;
                            line-height: 18px;
                            height: 18px;

                            .seat{
                                margin: 0 3px;
                            }
                        }
                    }
                }
            }
            .order-more{
                margin-left: 15px;
                display: flex;
                align-items: center;
                height: 37px;
                position: relative;

                .price{
                    line-height: 37px;
                    height: 37px;
                    font-size: 13px;
                    color: #888;
                    display: inline-block;
                }
                .right{
                    margin: 0 15px 0 auto;
                    color: #999;
                    font-size: 12px;
                    height: 24px;
                    line-height: 24px;

                    .bottom-btn{
                        display: inline-block;
                        margin-left: 5px;
                        border: 1px solid #ccc;
                        border-radius: 12px;
                        padding: 0 10px;
                    }
                }
                &::after{
                position: absolute;
                left: 0;
                top: 0;
                height: 1px;
                width: 100%;
                content: "";
                transform: scaleY(.5);
                transform-origin: 0 0;
                background: rgba(0,0,0,.1);
               }
            }
        }
        .order-item:last-child{
            margin-bottom: 60px;
        }
        &::-webkit-scrollbar {
        display: none;
      }
    }
    &::-webkit-scrollbar {
        display: none;
      }

}
::v-deep .van-overlay{
    display: flex;
    flex-direction: column;
    align-items: center;
     &::-webkit-scrollbar {
        display: none;
      }
}
.van-overlay img{
    position: absolute;
    width: 50%;
    height: 30%;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    margin: auto;
}
.van-overlay .font{
    position: absolute;
     width: 50%;
    height: 30%;
    top: 0;
    left: 20px;
    bottom: 50px;
    right: 0;
    margin: auto;
    color: #fff;
}
</style>